//
//  MeMessageDetailViewController.m
//  ChinaA
//
//  Created by Mxionlly on 2018/11/22.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "MeMessageDetailViewController.h"
#import <Masonry.h>
#import "MeMessageDetailViewCell.h"

@interface MeMessageDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView    *tableView;

@end

@implementation MeMessageDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"消息详情";
    [self setDefaultBackBtn];
}

-(void)setModel:(dataNewsInfo *)model
{
    _model = model;
    [self.tableView reloadData];
}

-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(self.view);
            make.top.mas_equalTo(self.view).offset(distanceHeight);
            make.bottom.mas_equalTo(self.view).offset(0);
        }];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor whiteColor];
        _tableView.scrollEnabled = YES;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
    }
    return _tableView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return .00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.model != nil) {
        CGSize SizeWidth = [self sizeWithText:self.model.MsgDes font:[UIFont systemFontOfSize:15] maxSize:CGSizeMake((KScreenWidth - 30), CGFLOAT_MAX)];
        return SizeWidth.height + 70;
    }
    return 100;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MeMessageDetailViewCell *cell = [MeMessageDetailViewCell cellWithTableView:tableView];
    cell.lbtitle.text = self.model.MsgTitle;
    cell.lbtime.text = self.model.CreateTime;
    cell.lbcontent.text = self.model.MsgDes;
    return cell;
}

- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
